package org.ndot.java.util;

import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * 【小蚂蚁学堂 - J2SE_Study】
 * 
 * 项目名称：J2SE_Study
 * 
 * 文件名：TestPriorityQueue.java
 * 
 * 功 能:
 * 
 * 
 * 作 者: SunJincheng
 * 
 * 创建时间: 2010-4-8
 * 
 */
public class TestPriorityQueue {
	public static void main(String[] args) {

		PriorityQueue<Integer> pq = new PriorityQueue<Integer>(20,
				new Comparator<Integer>() {
					public int compare(Integer i, Integer j) {
						int result = i % 2 - j % 2;
						if (result == 0)
							result = i - j;
						return result;
					}
				});

		// Fill up with data, in an odd order
		for (int i = 0; i < 20; i++) {
			pq.offer(20 - i);
		}

		// Print out and check ordering
		for (int i = 0; i < 20; i++) {
			System.out.println(pq.poll());
		}
	}

}
